package com.yunfeisoft.base.dao.impl;

import com.yunfeisoft.base.dao.inter.WorkflowInstanceDao;
import com.yunfeisoft.base.model.WorkflowDefine;
import com.yunfeisoft.base.model.WorkflowInstance;
import com.yunfeisoft.common.base.BaseDaoImpl;
import com.yunfeisoft.common.sql.builder.SelectBuilder;
import com.yunfeisoft.common.sql.builder.WhereBuilder;
import com.yunfeisoft.common.utils.Page;
import org.springframework.stereotype.Repository;

import java.util.Map;

/**
 * ClassName: WorkflowInstanceDaoImpl
 * Description: 流程实例Dao实现
 * Author: Jackie liu
 * Date: 2020-01-03
 */
@Repository
public class WorkflowInstanceDaoImpl extends BaseDaoImpl<WorkflowInstance, String> implements WorkflowInstanceDao {

    @Override
    public Page<WorkflowInstance> queryPage(Map<String, Object> params) {
        WhereBuilder wb = new WhereBuilder();
        wb.setOrderByWithDesc("createTime");
        if (params != null) {
            initPageParam(wb, params);
            wb.andEquals("i.status", params.get("status"));
            wb.andEquals("i.createId", params.get("createId"));
            wb.andFullLike("i.title", params.get("title"));
        }
        SelectBuilder builder = getSelectBuilder("i");
        builder.column("d.formPath as defineFormPath")
                .join(WorkflowDefine.class).alias("d").on("i.workflowDefineId = d.id").build();

        return queryPage(builder.getSql(), wb);
    }
}